<?
require_once("conn.php");
$id=$_REQUEST["id"];
?>
<table border="1" width="100%">
	<tr>
		<th width="100">หมายเลขการส่ง</th>
		<th width="200">Product</th>
		<th width="50">Send Amount</th>
		<th width="50">Real Amount</th>
		<th width="50">จำนวนของที่ขาด</th>
		<th width="100">Confirm By</th>
		<th width="150">Confirm Date</th>
		<th>รวมค้างส่ง (วัน)</th>
		<th>&nbsp;</th>
	</tr>
<?
	$sql = "select sendDate,checkDate,DATEDIFF(DATE(checkDate),DATE(sendDate)) as difDate FROM pch_sendisland as a JOIN pch_accept_order as b ON a.id=b.send_id WHERE b.id='".$id."';";
	$query = mysql_query($sql);
	$x = mysql_fetch_assoc($query);
	$diffDate = $x["difDate"];

	$sql = "SELECT a.id as id,send_id,th,mm,sendamount,realamount,confirmby,confirmDate,a.state as state FROM pch_accept_order_detail as a join product as b on a.item=b.id WHERE accept_id='".$id."';";
	$query = mysql_query($sql);
	while($row = mysql_fetch_array($query)){
		if($row["state"] == "0"){
			if($diffDate > 1){
				$diffShow = '<span style="color:red;font-weight:bold;">'.$diffDate.'</span>';
			}else{
				$diffShow = $diffDate;
			}
		}else{
			$diffShow = "Sended";
		}
	?>
		<tr>
			<td align="center"><?=$row["send_id"]?></td>
			<td><?=$row["th"]." | ".$row["mm"]?></td>
			<td align="center"><?=$row["sendamount"]?></td>
			<td align="center"><?=$row["realamount"]?></td>
			<td align="center"><?=($row["sendamount"] - $row["realamount"])?></td>
			<td align="center"><?=$row["confirmby"]?></td>
			<td align="center"><?=$row["confirmDate"]?></td>
			<td align="center"><?=$diffShow?></td>
			<td align="center">
				<?
				if($row["state"] == "0"){
				?>
					<a href="#" onclick="confirmSended('<?=$row["id"]?>')">Confirm</a>
				<?
				}else{
					echo "&nbsp;";
				}
				?>
			</td>
		</tr>
	<?
	}
?>
</table>